<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="郝珍华">
    <title></title>
   <link rel="stylesheet" href="百度新闻.css">
   
</head>

<body>
    <header>
        <div id="dakuang" class="clearfix">
            <div id="limian">
                <ul>
                    <li>
                        <a href="#">百度新闻客户端</a>
                    </li>
                    <li>
                        <a href="#">注册</a>
                    </li>
                    <li>
                        <a href="#">登录</a>
                    </li>
                    <li>
                        <a href="#">百度首页</a>
                    </li>
                </ul>
            </div>
            <div class="xiayi">
                <ul id="ling" class="clearfix">
                    <li>
                        <a href="#">网页</a>
                    </li>
                    <li style="margin-left:21px;">
                        <span>新闻</span>
                    </li>
                    <li>
                        <a href="#">贴吧</a>
                    </li>
                    <li>
                        <a href="#">知道</a>
                    </li>
                    <li>
                        <a href="#">音乐</a>
                    </li>
                    <li>
                        <a href="#">图片</a>
                    </li>
                    <li>
                        <a href="#">视频</a>
                    </li>
                    <li>
                        <a href="#">地图</a>
                    </li>
                    <li>
                        <a href="#">文库</a>
                    </li>
                    <div class="has"></div>
                </ul>
            </div>

        </div>
        <div id="dakuang1">
            <div class="container">
                <div class="lim">
                    <table class="light">
                        <tbody>
                            <tr>
                                <td class="logo">
                                    <div class="dake">
                                        <img src="百度新闻.png" alt="">
                                    </div>
                                    <div class="xiaoke"></div>
                                </td>
                                <td class="search">
                                    <table>
                                        <tbody>
                                            <tr>
                                                <td class="boo">
                                                    <div class="ght">
                                                        <span class="xiaokuang">
                                                        <input type="text" class="input1" size="42">
                                                    </span><span
                                                            class="xiaok">
                                                            <input type="submit" value="百度一下" class="baidu">
                                                            </span>
                                                    </div>
                                                </td>
                                                <td id="hell">
                                                    <a href="#">帮助</a>
                                                    <a href="#">高级搜索</a>
                                                    <a href="#">设置</a>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <p id="dian">
                                        <input type="radio" id="new" checked name="radio">
                                        <label class="check" for="new">新闻全文</label>
                                        <input type="radio" id="news" name="radio">
                                        <label class="notcheck" for="news">新闻标题</label>
                                    </p>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

        </div>
    </header>
    <nav class="nav">
        <div class="container">
            <ul class="nav-list clearfix">
                <!-- (li>a[href=#])*8 -->
                <li class="first"><a href="#">首页</a></li>
                <li><a href="#">百家号</a></li>
                <li><a href="#">国内</a></li>
                <li><a href="#">国际</a></li>
                <li><a href="#">军事</a></li>
                <li><a href="#">社会</a></li>
                <li><a href="#">财经</a></li>
                <li><a href="#">娱乐</a></li>
                <li><a href="#">体育</a></li>
                <li><a href="#">互联网</a></li>
                <li><a href="#">科技</a></li>
                <li><a href="#">游戏</a></li>
                <li><a href="#">时尚</a></li>
                <li><a href="#">女人</a></li>
                <li><a href="#">汽车</a></li>
                <li><a href="#">房产</a></li>
                <li><a href="#">个人推荐</a></li>
                <div class="bg"></div>
            </ul>
        </div>
    </nav>
    <div class="container">
        <main>

        </main>
    </div>
    <div class="back-to-top">返回顶部</div>
</body>

</html>
<script>
    var lis = document.querySelectorAll('.nav-list li');
    var bg = document.querySelector('.bg');
    for (var i = 0; i < lis.length; i++) {
        // 鼠标进来 改变 bg的位置和宽度
        lis[i].onmouseover = function () {

            //  console.log(this.offsetLeft);
            // 元素距离容器左边的偏移距离
            var left = this.offsetLeft;
            // 设置bg的偏移距离
            bg.style.left = left + 'px';
            // 获取标签的宽度
            var width = this.offsetWidth;
            bg.style.width = width + 'px';
        }
        // 鼠标出去的时候，回复bg的位置和宽度
        lis[i].onmouseout = function () {
            bg.style.left = 0;
            bg.style.width = '60px';
        }
    }
    // 点击返回顶部
    var backToTop = document.querySelector('.back-to-top');
    backToTop.onclick = function () {
        document.documentElement.scrollTop = document.body.scrollTop = 0;

    }


    //  动态固定位置
    var nav = document.querySelector('.nav');
    window.onscroll = function () {
        var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
        //  查看nav下拉多少的高度，直至达到顶部固定
        console.log(scrollTop);
        // 固定nav
        if (scrollTop >= 120) {
            // 固定nav
            nav.style.position = 'fixed';
            nav.style.top = '0';
        } else {
            // 去除固定位置的效果
            nav.style.position = 'static';
        }
        // 当页面卷去的大小超过300时，出现返回顶部的按钮
        // 否则，隐藏
        if (scrollTop > 300) {
            backToTop.style.bottom = '30px';

        } else {
            backToTop.style.bottom = '-30px';
        }


    }

</script>